<?php

class Wlib_Doctrine_Migration_Base extends Doctrine_Migration_Base
{
    /**
     * @var string|Array Один sql-запрос или массив
     */
    protected $_upSql = null;

    /**
     * @var string|Array Один sql-запрос или массив
     */
    protected $_downSql = null;

    public function __construct()
    {
        if(!$this->_upSql && !$this->_downSql) {
            throw new Doctrine_Migration_Exception('You must define _upSql and _downSql');
        }
    }

    public function getConnection()
    {
        return Doctrine_Manager::connection();
    }

    public function up()
    {
        $this->execSql($this->_upSql);
    }

    public function down()
    {
        $this->execSql($this->_downSql);
    }

    public function execSql($sql)
    {
        $sql = (array) $sql;

        foreach($sql as $execSql) {
            $this->getConnection()->exec($execSql);
        }
    }
}